import os
from spyder import TrainingChina
print("欢迎使用NIIT刷课系统")
o = TrainingChina()
username = input("请输入Niit注册号：")
password = input("请输入密码：")
_ = o.login_with_plain(username=username,password=password)
if _["code"] is 200:
    print("登录成功")
    os.system("cls")
    print("请求中》》》")
    course_list = o.get_courses()
    os.system("cls")
    print("请选择您要学习的课程模块：(输入对应数字即可，多门课请用英文半角逗号分隔)")
    for index,t in enumerate(course_list):
        print(str(index+1)+". "+t["name"])
    index_list = input("请输入：")
    os.system("cls")
    print("请求中》》》")
    class_list = list()
    for t in index_list.split(","):
        index = int(t) -1
        course_url = course_list[index]["href"]
        course_name = course_list[index]["name"]
        class_list.extend(o.get_classes(course_url=course_url,course_name=course_name))
    os.system("cls")
    print("请选择您要学习的讲座：(输入对应数字即可，多门课请用英文半角逗号分隔)")
    for index,t in enumerate(class_list):
        print(str(index+1)+". "+t["name"])
    index_list = input("请输入：")
    for t in index_list.split(","):
        index = int(t) -1
        print(class_list[index]["name"],"刷课ing~~~")
        response = o.finish_class(class_list[index]["href"])
        if response["code"] is 200:
            print(class_list[index]["name"],"刷课完成")
else:
    print(response)